#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}
const int N = 1<<18;

int a[N],n,m,x,y,f[N];
ll ans;
int gf(int x){return f[x] == x ? f[x] : f[x] = gf(f[x]);}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 0;i <= 1<<m;i++) f[i] = i;
	for(int i = 1;i <= n;i++) x = in,a[x] ? ans += x : a[x] = x;
	for(int i = (1<<m) - 1;i>=0;i--){
		for(int j = 0;j < m && !a[i];j++) a[i] = a[i | (1<<j)]; x = gf(a[i]);
		for(int j = 0;j < m;j++) if((y = a[1 << j | i]) && gf(y) != x) ans += i,f[gf(y)] = x;
	}
	printf("%lld\n",ans);
	return 0;
}

